fix: Don't report check to invalid sha#515
Merged
timja merged 4 commits intojenkinsci:masterfrom Feb 20, 2026
Merged
Conversation
This fixes an issue where a failed git checkout (because of a missing
ref, network, or auth issues) would cause a failure to be posted to
GitHub for the wrong sha - most often the last successfully built sha.
This has caused confusion when one or more checks was reported as
passing only to be unexpectedly changed to failing for an unrelated
reason. It looks for cases where the git build data doesn't match the
current build and returning an empty string for the sha if that's the
case. Otherwise the behavior should remain the same.
I added a new test to cover this case and I've tested it both with a
manual repro in a sandbox environment and in a production environment
(we run approximately 100k PR checks through this plugin on an average
day) to confirm that it's working as expected when build failures occur
before or during checkout.
Prior to this fix - a failure during git checkout would report the
failure to the previous successful sha:
```
> gh api "repos/$ORG/$REPO/commits/$SHA/check-runs?filter=all" | jq
'.check_runs[] | {name, head_sha, status, conclusion, completed_at}'
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "71a1cc8f8b956b11b12036b8687acd7a5fafa868",
"status": "completed",
"conclusion": "failure",
"completed_at": "2026-02-18T15:49:53Z"
}
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "71a1cc8f8b956b11b12036b8687acd7a5fafa868",
"status": "completed",
"conclusion": "success",
"completed_at": "2026-02-18T15:48:46Z"
}
```
And with this fix, the build failed. But, as expected, it skipped
reporting the failure to the wrong sha:
```
> gh api "repos/$ORG/$REPO/commits/$SHA/check-runs?filter=all" | jq
'.check_runs[] | {name, head_sha, status, conclusion, completed_at}'
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "5dd2fbbbf2d102e0bb72f1ab76e5c00b8b29cf2e",
"status": "completed",
"conclusion": "success",
"completed_at": "2026-02-18T15:58:32Z"
}
```
The main caveat with this is that we use Freestyle jobs, not Pipeline
jobs, so I'm relying on the existing test case to ensure it's still
working as expected for pipelines.
I had made the original changes based on an older version of the plugin so it would be compatible with the older version of Jenkins we're still using and I forgot to re-run the tests after I cherry-picked the commit to the latest on `master`. This is now passing when I run tests locally.
Contributor
Author
|
Seeing more failures coming in - I'll work on fixing them later today! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #515 +/- ##
============================================
- Coverage 71.80% 71.64% -0.17%
- Complexity 162 163 +1
============================================
Files 16 16
Lines 532 536 +4
Branches 51 53 +2
============================================
+ Hits 382 384 +2
Misses 124 124
- Partials 26 28 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes #460, where a failed git checkout (because of a missing ref, network, or auth issues) would cause a failure to be posted to GitHub for the wrong sha. Most often the last successfully built sha. This can cause confusion when one or more checks was reported as passing only to be unexpectedly changed to failing for an unrelated reason. It looks for cases where the git build data doesn't match the current build and returning an empty string for the sha if that's the case. Otherwise the behavior should remain the same.
Testing done
I added a new test to cover this case and I've tested it both with a manual repro in a sandbox environment and in a production environment (we run approximately 100k PR checks through this plugin on an average day) to confirm that it's working as expected when build failures occur before or during checkout.
Prior to this fix - a failure during git checkout, in this case because of a nonexistent ref, would report the failure to the previous successful sha:
And with the fix, the build skipped reporting the failure to the wrong sha:
The main caveat with this is that we use Freestyle jobs, not Pipeline jobs, so I'm relying on the existing test case to ensure it's still working as expected for pipelines.
Submitter checklist